import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        /*登录*/
        user: null,             //存储的用户信息
        isLogin: false,         //是否登录
        saving: false ,         // 保存时候loading控制开关
        funtionType:[],         // 客户具备的功能
        /*客户*/
        vueContact:{},          //客户新增页面对象
        vueCusMan:{},           //customerManage页面数据
        vueCustomerView:{},     //customerView页面数据
        vueAddLinkMan:{},       //新增联系人页面 编辑联系人时用
        vueLinkManManage:{},    //联系人管理页面数据对象
        index:1,                //新增联系人位置识别 0为添加客户位置
        /*售前*/
        vueOppotunity:{},       //销售机会页面对象
        vueActrecord:{},        //行动记录页面对象
        /*售中*/
        vueContracte:{},        //合同页面的对象
        contract:{},            // 合同
        /*产品管理*/
        vueAppCai:{},           //主页面数据
        vueDetail:{},           //弹框页面数据
        vueProduct:{},          //product页面数据
        vueAddProduct:{},       //add_product页面数据
        vueAddAttribute:{},     //add_attribute页面数据
    },
    mutations: {
         /*登录*/
        //更改用户状态
        setUserStatus(state, user) {
            if (user) {
                state.user = user;
                state.isLogin = true;
            } else {
                state.user = null;
                state.isLogin = false;
                localStorage.removeItem('isLogin')
                localStorage.removeItem('user')
            }
        },
        setFuntionType(state,obj){
            state.funtionType = obj
        },
        /*售前*/
        setVueOppotunity(state,obj){
            state.vueOppotunity = obj
        },
        setVueActrecord(state,obj){
            state.vueActrecord = obj
        },
        /*售中*/
        setVueContracte(state, obj){
            state.vueContracte = obj
        },
        setContract(state, obj){
            state.contract = obj
        },
        /*客户*/
        setVueContact(state,obj){
            state.vueContact = obj
        },
        setVueLinkManManage(state,obj){
            state.vueLinkManManage = obj
        },
        setVueCustomerView(state,obj){
            state.vueCustomerView = obj
        },
        setIndex(state,index){
            state.index = index
        },
        setVueCusMan(state,obj){
            state.vueCusMan = obj
        },
        setVueAddLinkMan(state,obj){
            state.vueAddLinkMan = obj
        },
        /*产品管理*/
        setVueProduct(state,obj){
            state.vueProduct=obj
        },
        setVueAddProduct(state,obj){
            state.vueAddProduct=obj
        },
        setVueAddAttribute(state,obj){
            state.vueAddAttribute=obj
        },
        setVueAppCai(state,obj){
            state.vueAppCai=obj
        },
        setVueDetail(state,obj){
            state.vueDetail=obj
        },
        /* 保存时候loading控制开关 */
        setSaving(state,obj){
            state.saving = obj
        },
    },
    actions: {
        /*登录*/
        setUserStatus : ({ commit }, user) => commit('setUserStatus',user),
        setFuntionType : ({ commit }, obj) => commit('setFuntionType',obj),
        /*售前*/
        setVueOppotunity : ({commit},obj) => commit('setVueOppotunity',obj),
        setVueActrecord : ({commit,obj}) => commit('setVueActrecord',obj),
        /*售中*/
        setVueContracte : ({ commit }, obj) => commit('setVueContracte', obj),
        setContract : ({ commit }, obj) => commit('setContract', obj),
        /*客户*/
        setVueContact : ({ commit }, obj) => commit('setVueContact', obj),
        setVueLinkManManage : ({ commit }, obj) => commit('setVueLinkManManage', obj),
        setVueCustomerView : ({ commit }, obj) => commit('setVueCustomerView', obj),
        setIndex : ({ commit }, index) => commit('setIndex', index),
        setVueCusMan : ({ commit }, vueCusMan) => commit('setVueCusMan', vueCusMan),
        setVueAddLinkMan : ({commit,obj}) => commit('setVueAddLinkMan',obj),
        /*产品管理*/
        setVueProduct:({commit},vueProduct)=>commit('setVueProduct',vueProduct),
        setVueAddProduct:({commit},vueAddProduct)=>commit('setVueAddProduct',vueAddProduct),
        setVueAddAttribute:({commit},vueAddAttribute)=>commit('setVueAddAttribute',vueAddAttribute),
        setVueAppCai:({commit},obj)=>commit('setVueAppCai',obj),
        setVueDetail:({commit},obj)=>commit('setVueDetail',obj),
        /* 保存时候loading控制开关 */
        setSaving:({commit},obj)=>commit('setSaving',obj),
    },
    getters: {
        /*登录*/
        user: state => state.user,
        isLogin: state => state.isLogin,
        funtionType: state => state.funtionType,
        /*售前*/
        setVueOppotunity:state => state.vueOppotunity,
        vueActrecord:state => state.vueActrecord,
        /*售中*/
        vueContracte: state => state.vueContracte,
        contract: state => state.contract,
        /*客户*/
        setVueContact: state => state.vueContact,
        setVueLinkManManage: state => state.setVueLinkManManage,
        setVueCustomerView: state => state.setVueCustomerView,
        setIndex:state => state.index,
        setVueCusMan:state => state.vueCusMan,
        setVueAddLinkMan:state => state.vueAddLinkMan,
        /*产品管理*/
        setVueProduct:state => state.vueProduct,
        setVueAddProduct:state => state.vueAddProduct,
        setVueAddAttribute:state => state.vueAddAttribute,
        setVueAppCai:state => state.vueAppCai,
        setVueDetail:state=>state.vueDetail,
        /* 保存时候loading控制开关 */
        saving:state => state.saving,
    },
    modules: {}
});
